{include file="header"}
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="postheader">
                <div class="w35">
                    <i class="layui-icon">&#xe6ed;</i>
                    漫画信息录入窗口
                </div>
                <div class="w25"><span class="x-red">*</span>作品名:<span class="x-red">{$work.title}</span> </div>

            </div>
            <input type="hidden" name="dbname" value="comics">
            <input type="hidden" name="id" value="{$item.id}">
            <input type="hidden" name="work_id" value="{$item.work_id}">

            <fieldset class="layui-elem-field" style="margin-top: 50px;">
                <legend>基本信息</legend>
                <div class="layui-field-box">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label childlabel"><span class="x-red">*</span>总话数:</label>
                            <div class="layui-inline">
                                File.<input type="text" name="words1" data-check="1" value="{$item.words1}" required  lay-verify="required" autocomplete="off" class="layui-input number" style="width: 70px;display: inline-block;">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label childlabel"><span class="x-red">*</span>单行本</label>
                            <div class="layui-inline">
                                第<input type="text" name="comics_rolls" value="{$item.comics_rolls}" required  lay-verify="required" autocomplete="off" class="layui-input number" style="width: 70px;display: inline-block;">卷
                            </div>
                            <div class="layui-inline">
                                File.<input type="text" name="comics_rolls_file" value="{$item.comics_rolls_file}" required  lay-verify="required" autocomplete="off" class="layui-input number" style="width: 70px;display: inline-block;">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label childlabel"><span class="x-red"></span>封面人物:</label>
                            <div class="layui-inline">
                                <input type="text" name="thumb" value="{$item.thumb}"  autocomplete="off" class="layui-input" >
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label childlabel"><span class="x-red"></span>发售日期:</label>
                            <div class="layui-inline">
                                <input type="text" id="release_date" name="release_date" value="{$item.release_date}"  autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label childlabel"><span class="x-red">*</span>标题名称(中)</label>
                            <div class="layui-input-inline">
                                <input type="text" name="title" value="{$item.title}" lay-verify="required" autocomplete="off" class="layui-input" >
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label childlabel"><span class="x-red">*</span>(日)</label>
                            <div class="layui-input-inline">
                                <input type="text" name="title_jp" value="{$item.title_jp}" lay-verify="required" autocomplete="off" class="layui-input" >
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label childlabel"><span class="x-red"></span>杂志刊号:</label>
                            <div class="layui-inline">
                                <input type="text" name="year" value="{$item.year}" autocomplete="off" class="layui-input nosel" style="width: 70px;display: inline-block;">年
                            </div>
                            <div class="layui-inline">
                                <input type="text" name="num1" value="{$item.num1}" autocomplete="off" class="layui-input nosel" style="width: 70px;display: inline-block;">
                            </div>
                            <div class="layui-inline num2" {if !$item.num2}style="display: none;"{/if}>
                                ·<input type="text" name="num2" value="{$item.num2}" autocomplete="off" class="layui-input" style="width: 70px;display: inline-block;">
                            </div>
                            <div class="layui-inline">号</div>
                            <div class="layui-inline num2" {if !$item.num2}style="display: none;"{/if}>（合）</div>
                            <div class="layui-inline">
                                {if !$item.num2}
                                <a href="javascript:;" class="iconsubadd add" id="num2btn">+</a>
                                {else}
                                <a href="javascript:;" class="iconsubadd sub" id="num2btn">-</a>
                                {/if}
                            </div>
                        </div>
                        <div class="layui-inline">
                            <input type="radio" lay-filter="typec" name="typec" value="1" title="正常" {if $item.typec eq 1}checked{/if}>
                            <input type="radio" lay-filter="typec" name="typec" value="2" title="休刊" {if $item.typec eq 2}checked{/if}>
                            <input type="radio" lay-filter="typec" name="typec" value="3" title="因上次合刊而停售" {if $item.typec eq 3}checked{/if}>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label childlabel"><span class="x-red"></span>首更日期:</label>
                            <div class="layui-inline">
                                <input type="text" id="add_time" name="add_time" value="{$item.add_time}"  autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <input type="hidden" name="display" value="0">
                        <button  type="button" class="layui-btn" lay-filter="add" lay-submit="">
                            提交
                        </button>
                        <button  class="layui-btn layui-btn-primary" type="button" lay-filter="temporary" lay-submit="">
                            暂存
                        </button>
                        <button  class="layui-btn layui-btn-primary cancel" type="button">
                            取消
                        </button>
                    </div>
                </div>
            </fieldset>
        </form>
    </div>
</div>
<script>
    layui.use(['laydate'],function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#release_date' //指定元素
            ,type:"date"
            ,format:"yyyy年MM月dd日"
        });
        laydate.render({
            elem: '#add_time' //指定元素
            ,type:"date"
            ,format:"yyyy年MM月dd日"
        });
        $('#num2btn').click(function () {
            if($(this).hasClass("add")){
                $(this).removeClass("add")
                $(this).addClass("sub")
                $(this).text("-");
                $('.num2').show()
            }else{
                $(this).addClass("add")
                $(this).removeClass("sub")
                $(this).text("+");
                $('[name="num2"]').val(null)
                $('.num2').hide()
            }
        })
        form.on('radio(typec)', function(data){
            var val = data.value
            if(val!=1){
                $('.num2').hide()
                $('#num2btn').hide()
                $('.nosel').attr("disabled",true)
                $('.nosel').css("backgroundColor","#e6e6e6")
            }else{
                $('.nosel').attr("disabled",false)
                $('.nosel').css("backgroundColor","#fff")
                $('#num2btn').show()
            }
        });
        //监听提交
        form.on('submit(temporary)', function(data) {

            data.field.display=1

            request("POST",'{:url("comics/post")}',data.field,function (res,msg) {
                //发异步，把数据提交给php
                layer.alert(msg, {icon: 6}, function() {
                    xadmin.close();
                    // 可以对父窗口进行刷新
                    xadmin.father_reload();
                });
            })

            return false;
        });
        //监听提交
        form.on('submit(add)', function(data) {
            request("POST",'{:url("comics/post")}',data.field,function (res,msg) {
                //发异步，把数据提交给php
                layer.alert(msg, {icon: 6}, function() {
                    xadmin.close();
                    // 可以对父窗口进行刷新
                    xadmin.father_reload();
                });
            })

            return false;
        });
    })
    $(document).on("change", '.number', function () {
        var field = $(this).attr("name")
        var num = parseInt($(this).val())
        var _this = $(this)

        if(isNaN(num) || num<=0){
            layui.msg("请输入数字")
            _this.val(null)
        }else{
            if(field=="comics_rolls"){
                var work_id = '{$item.work_id}'
                var url = '{:url("comics/post")}'
                request("GET",url,{work_id:work_id,comics_rolls:num},function (res,msg) {
                    var formData = {}
                    formData[`thumb`] = res.thumb
                    formData[`release_date`] = res.release_date

                    formSetVal(formData)
                })
            }
        }
    })
</script>
{include file="footer"}